#!/bin/bash 
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage4}
SRC=${SRC:-/sources}

name=pcre
version=8.44

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.bz2 -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
	./configure --prefix=/usr                          \
	            --docdir=/usr/share/doc/$name-$version \
	            --enable-unicode-properties            \
	            --enable-pcre16                        \
	            --enable-pcre32                        \
	            --enable-pcregrep-libz                 \
	            --enable-pcregrep-libbz2               \
	            --enable-pcretest-libreadline          \
	            --disable-static
	make

	make install
	mv -v /usr/lib/libpcre.so.* /lib
	ln -sfv ../../lib/$(readlink /usr/lib/libpcre.so) /usr/lib/libpcre.so

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
